package com.com.hemoWork.work2;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class TcpCilentFile {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("192.168.191.137", 8089);

        String next = new Scanner(System.in).next();
        System.out.println("请输入文件的路径:");

        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(socket.getOutputStream());
        // File file=new File(next);
        InputStream is = new FileInputStream(new File(next));
        Reader reader = new InputStreamReader(is);

        char[] buffer = new char[1024];
        int len = 0;
        while ((len = reader.read(buffer)) != -1) {
            String str = new String(buffer, 0, len);
            //文件的内容
            // System.out.println(str);

            OutputStream outputStream = socket.getOutputStream();
            outputStream.write(str.getBytes());
        }

        reader.close();
        //关闭socket，否则出现Connection reset
        socket.close();
        is.close();


    }
}
